package com.trace.learn;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * 线程池 传递
 * @author chenxin
 * @time 2017-03-19-09:12
 */
public class ExecutorPassTest {
    private static ThreadLocal<String> threadLocal = new ThreadLocal<String>();

    public static void main(String[] args) {
        Executor executor = Executors.newCachedThreadPool();

        threadLocal.set("parent thread value");
        Runnable runnable1 = new MyRunnable();

        executor.execute(runnable1);

        System.out.println(Thread.currentThread().getName() + " " + threadLocal.get());
    }

    private static class MyRunnable implements Runnable{
        @Override public void run() {
            System.out.println("runnable get =" + threadLocal.get());
        }
    }
}
